
import java.awt.Cursor;
import java.awt.Image;
import java.io.File;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;

public class frm_pacientes extends javax.swing.JFrame {

    public static String nivel_acesso;
    /** Creates new form frm_clinicas */
    public frm_pacientes(String nivel_acesso) {
        this.nivel_acesso = nivel_acesso;
        initComponents();
        try {  
            javax.swing.UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");  
            javax.swing.SwingUtilities.updateComponentTreeUI(this);  
        } catch (Exception e) {  
        e.printStackTrace();  
        }
        btn_salvar.setEnabled(false);
        setExtendedState(MAXIMIZED_BOTH);
        nomeBotoes();
        maoBotoes();
        DentistaController dentistaController = new DentistaController();
        dentistaController.listarDentistasCombo();
        jFileChooser.setVisible(false);
        verificarNivelAcesso();
    }

    int id_paciente;
    int id_dentista;
    String nome_dentista;
    String nome;
    String apto;
    String bairro;
    String celular;
    String cidade;
    String rg;
    String email;
    String endereco;
    String numero;
    String cpf;
    String telefone;
    String uf;
    
    
    public void verificarNivelAcesso(){
        if(nivel_acesso.equals("Operador")){
            jm_menu_usuarios.setEnabled(false);
            jm_menu_usuarios.setVisible(false);       
        }
        else{
            jm_menu_usuarios.setEnabled(true);
            jm_menu_usuarios.setVisible(true);
        }
    }
    
    public void habilitarCampos(){
        tf_nome.setEditable(true);
        tf_apto.setEditable(true);
        tf_cpf.setEditable(true);
        tf_rg.setEditable(true);
        tf_bairro.setEditable(true);
        tf_celular.setEditable(true);
        tf_cidade.setEditable(true);
        tf_email.setEditable(true);
        tf_endereco.setEditable(true);
        tf_numero.setEditable(true);
        tf_telefone.setEditable(true);
    }
    
    public void desabilitarCampos(){
        tf_nome.setEditable(false);
        tf_apto.setEditable(false);
        tf_cpf.setEditable(false);
        tf_rg.setEditable(false);
        tf_bairro.setEditable(false);
        tf_celular.setEditable(false);
        tf_cidade.setEditable(false);
        tf_email.setEditable(false);
        tf_endereco.setEditable(false);
        tf_numero.setEditable(false);
        tf_telefone.setEditable(false);
    }
    
    public void limparCampos(){
        tf_nome.setText("");
        tf_cpf.setText("");
        tf_apto.setText("");
        tf_bairro.setText("");
        tf_celular.setText("");
        tf_cidade.setText("");
        tf_rg.setText("");
        tf_cpf.setText("");
        tf_codigo.setText("");
        tf_email.setText("");
        tf_endereco.setText("");
        tf_telefone.setText("");
        tf_numero.setText("");
        cb_uf.setSelectedIndex(0);
        cb_dentista.setSelectedIndex(0);
        tf_codigo.setText("");
    }
    
    public void incrementarCodigo(){
        PacienteController pacienteController = new PacienteController();
        tf_codigo.setText(pacienteController.buscarIDProx("id_paciente") + "");
    }
    
    /*
    * Método para validar se campos obrigatorios para o cadastro
    * estao corretamente preenchidos.
    */
    public boolean validarFormulario(){
        if(nome.equals("")||telefone.equals("")
                ||endereco.equals("")||cidade.equals("")||cb_dentista.getSelectedItem().equals("Selecione um dentista")){
            return false;
        }
        else{
            return true;
        }
    }
    
    /*
     * Método que busca a qtd de linhas e colunas
     * para limpar a tabela dentistas.
     */
    public void limparTabelaPacientes(){
       int linha = jt_pacientes.getRowCount();
       int coluna = jt_pacientes.getColumnCount();
       for(int i=0; i<linha; i++) 
           for(int j=0; j<coluna; j++){
               jt_pacientes.setValueAt("", i, j);
           }
    }
    
    public void nomeBotoes(){
        btn_novo.setToolTipText("Novo cadastro");
        btn_salvar.setToolTipText("Salvar");
        btn_excluir.setToolTipText("Excluir");
        btn_editar.setToolTipText("Editar");
        btn_alterar.setToolTipText("Alterar");
    }

    public void maoBotoes(){
        btn_novo.setCursor(new Cursor(Cursor.HAND_CURSOR));
        btn_salvar.setCursor(new Cursor(Cursor.HAND_CURSOR));
        btn_excluir.setCursor(new Cursor(Cursor.HAND_CURSOR));
        btn_editar.setCursor(new Cursor(Cursor.HAND_CURSOR));
        btn_alterar.setCursor(new Cursor(Cursor.HAND_CURSOR));        
    }
    
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jp_dados_do_paciente = new javax.swing.JPanel();
        lbl_codigo = new javax.swing.JLabel();
        tf_codigo = new javax.swing.JTextField();
        lbl_nome = new javax.swing.JLabel();
        tf_nome = new javax.swing.JTextField();
        lbl_rg = new javax.swing.JLabel();
        tf_rg = new javax.swing.JFormattedTextField();
        lbl_cpf = new javax.swing.JLabel();
        tf_cpf = new javax.swing.JFormattedTextField();
        lbl_dentista = new javax.swing.JLabel();
        cb_dentista = new javax.swing.JComboBox();
        jp_dados_residenciais = new javax.swing.JPanel();
        lbl_endereco = new javax.swing.JLabel();
        tf_endereco = new javax.swing.JTextField();
        lbl_numero = new javax.swing.JLabel();
        tf_numero = new javax.swing.JTextField();
        lbl_cidade = new javax.swing.JLabel();
        tf_cidade = new javax.swing.JTextField();
        lbl_bairro = new javax.swing.JLabel();
        tf_bairro = new javax.swing.JTextField();
        lbl_apto = new javax.swing.JLabel();
        tf_apto = new javax.swing.JTextField();
        lbl_uf = new javax.swing.JLabel();
        cb_uf = new javax.swing.JComboBox();
        jp_dados_de_contato = new javax.swing.JPanel();
        lbl_email = new javax.swing.JLabel();
        tf_email = new javax.swing.JTextField();
        lbl_fone_fax = new javax.swing.JLabel();
        tf_telefone = new javax.swing.JFormattedTextField();
        lbl_celular = new javax.swing.JLabel();
        tf_celular = new javax.swing.JFormattedTextField();
        jp_pesquisa = new javax.swing.JPanel();
        lbl_filtrar = new javax.swing.JLabel();
        cb_filtrar = new javax.swing.JComboBox();
        lbl_igual = new javax.swing.JLabel();
        tf_pesquisar = new javax.swing.JTextField();
        btn_pesquisar = new javax.swing.JButton();
        jp_paciente = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jt_pacientes = new javax.swing.JTable();
        jPanel1 = new javax.swing.JPanel();
        btn_novo = new javax.swing.JButton();
        btn_excluir = new javax.swing.JButton();
        btn_salvar = new javax.swing.JButton();
        btn_alterar = new javax.swing.JButton();
        btn_editar = new javax.swing.JButton();
        btn_imagem = new javax.swing.JButton();
        jFileChooser = new javax.swing.JFileChooser();
        jLabel1 = new javax.swing.JLabel();
        jm_menu = new javax.swing.JMenuBar();
        jm_menu_opcoes = new javax.swing.JMenu();
        jm_menu_backup = new javax.swing.JMenuItem();
        jm_menu_restaurar_backup = new javax.swing.JMenuItem();
        jm_menu_usuarios = new javax.swing.JMenuItem();
        jm_menu_sair = new javax.swing.JMenuItem();
        jm_menu_gerenciar = new javax.swing.JMenu();
        jm_menu_clinicas = new javax.swing.JMenuItem();
        jm_menu_dentistas = new javax.swing.JMenuItem();
        jm_menu_pacientes = new javax.swing.JMenuItem();
        jm_menu_ordem_de_servico = new javax.swing.JMenuItem();
        jm_menu_ajuda = new javax.swing.JMenu();
        jm_menu_conteudo_ajuda = new javax.swing.JMenuItem();
        jm_menu_sobre = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Clínica de Próteses | Pacientes");

        jp_dados_do_paciente.setBackground(new java.awt.Color(255, 255, 255));
        jp_dados_do_paciente.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Dados do(a) Paciente:", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Calibri", 1, 18), new java.awt.Color(0, 102, 153))); // NOI18N
        jp_dados_do_paciente.setForeground(new java.awt.Color(255, 255, 255));

        lbl_codigo.setFont(new java.awt.Font("Calibri", 1, 16)); // NOI18N
        lbl_codigo.setText("Código:");

        tf_codigo.setEditable(false);
        tf_codigo.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N

        lbl_nome.setFont(new java.awt.Font("Calibri", 1, 16)); // NOI18N
        lbl_nome.setText("Nome:*");

        tf_nome.setEditable(false);
        tf_nome.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N

        lbl_rg.setFont(new java.awt.Font("Calibri", 1, 16)); // NOI18N
        lbl_rg.setText("RG:");

        tf_rg.setEditable(false);
        tf_rg.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N

        lbl_cpf.setFont(new java.awt.Font("Calibri", 1, 16)); // NOI18N
        lbl_cpf.setText("CPF:");

        tf_cpf.setEditable(false);
        try {
            tf_cpf.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("###.###.###-##")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        tf_cpf.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N

        lbl_dentista.setFont(new java.awt.Font("Calibri", 1, 16)); // NOI18N
        lbl_dentista.setText("Dentista:* ");

        cb_dentista.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N
        cb_dentista.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Selecione um dentista", "Não possui" }));

        javax.swing.GroupLayout jp_dados_do_pacienteLayout = new javax.swing.GroupLayout(jp_dados_do_paciente);
        jp_dados_do_paciente.setLayout(jp_dados_do_pacienteLayout);
        jp_dados_do_pacienteLayout.setHorizontalGroup(
            jp_dados_do_pacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jp_dados_do_pacienteLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jp_dados_do_pacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jp_dados_do_pacienteLayout.createSequentialGroup()
                        .addComponent(lbl_dentista)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(cb_dentista, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(jp_dados_do_pacienteLayout.createSequentialGroup()
                        .addGroup(jp_dados_do_pacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lbl_codigo)
                            .addComponent(lbl_nome)
                            .addComponent(lbl_cpf)
                            .addComponent(lbl_rg))
                        .addGap(30, 30, 30)
                        .addGroup(jp_dados_do_pacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(tf_nome, javax.swing.GroupLayout.PREFERRED_SIZE, 273, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(tf_codigo, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jp_dados_do_pacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(tf_rg, javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(tf_cpf, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 170, Short.MAX_VALUE)))))
                .addContainerGap(253, Short.MAX_VALUE))
        );
        jp_dados_do_pacienteLayout.setVerticalGroup(
            jp_dados_do_pacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jp_dados_do_pacienteLayout.createSequentialGroup()
                .addGroup(jp_dados_do_pacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tf_codigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbl_codigo))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jp_dados_do_pacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(cb_dentista, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                    .addComponent(lbl_dentista))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jp_dados_do_pacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbl_nome)
                    .addComponent(tf_nome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jp_dados_do_pacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(tf_rg, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbl_rg))
                .addGap(11, 11, 11)
                .addGroup(jp_dados_do_pacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbl_cpf)
                    .addComponent(tf_cpf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(6, 6, 6))
        );

        jp_dados_residenciais.setBackground(new java.awt.Color(255, 255, 255));
        jp_dados_residenciais.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Dados Residênciais:", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Calibri", 1, 18), new java.awt.Color(0, 102, 153))); // NOI18N

        lbl_endereco.setFont(new java.awt.Font("Calibri", 1, 16)); // NOI18N
        lbl_endereco.setText("Endereço:*");

        tf_endereco.setEditable(false);
        tf_endereco.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N

        lbl_numero.setFont(new java.awt.Font("Calibri", 1, 16)); // NOI18N
        lbl_numero.setText("Número:");

        tf_numero.setEditable(false);
        tf_numero.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N

        lbl_cidade.setFont(new java.awt.Font("Calibri", 1, 16)); // NOI18N
        lbl_cidade.setText("Cidade:*");

        tf_cidade.setEditable(false);
        tf_cidade.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N

        lbl_bairro.setFont(new java.awt.Font("Calibri", 1, 16)); // NOI18N
        lbl_bairro.setText("Bairro:");

        tf_bairro.setEditable(false);
        tf_bairro.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N

        lbl_apto.setFont(new java.awt.Font("Calibri", 1, 16)); // NOI18N
        lbl_apto.setText("Apto:");

        tf_apto.setEditable(false);
        tf_apto.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N

        lbl_uf.setFont(new java.awt.Font("Calibri", 1, 16)); // NOI18N
        lbl_uf.setText("UF:");

        cb_uf.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N
        cb_uf.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "AC", "AL", "AP", "AM", "BA", "CE", "DF", "ES", "GO", "MA", "MT", "MS", "MG", "PA", "PB", "PR", "PE", "PI", "RJ", "RN", "RS", "RO", "RR", "SC", "SP", "SE", "TO" }));

        javax.swing.GroupLayout jp_dados_residenciaisLayout = new javax.swing.GroupLayout(jp_dados_residenciais);
        jp_dados_residenciais.setLayout(jp_dados_residenciaisLayout);
        jp_dados_residenciaisLayout.setHorizontalGroup(
            jp_dados_residenciaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jp_dados_residenciaisLayout.createSequentialGroup()
                .addGroup(jp_dados_residenciaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jp_dados_residenciaisLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jp_dados_residenciaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lbl_endereco)
                            .addGroup(jp_dados_residenciaisLayout.createSequentialGroup()
                                .addGroup(jp_dados_residenciaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(lbl_apto)
                                    .addComponent(lbl_cidade))
                                .addGap(20, 20, 20)
                                .addGroup(jp_dados_residenciaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addGroup(jp_dados_residenciaisLayout.createSequentialGroup()
                                        .addComponent(tf_apto, javax.swing.GroupLayout.PREFERRED_SIZE, 164, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(46, 46, 46))
                                    .addGroup(jp_dados_residenciaisLayout.createSequentialGroup()
                                        .addComponent(tf_cidade)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)))
                                .addGroup(jp_dados_residenciaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(lbl_bairro)
                                    .addComponent(lbl_uf))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jp_dados_residenciaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(tf_bairro, javax.swing.GroupLayout.DEFAULT_SIZE, 223, Short.MAX_VALUE)
                                    .addComponent(cb_uf, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                    .addGroup(jp_dados_residenciaisLayout.createSequentialGroup()
                        .addGap(88, 88, 88)
                        .addComponent(tf_endereco, javax.swing.GroupLayout.PREFERRED_SIZE, 335, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(lbl_numero)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(tf_numero)))
                .addContainerGap(48, Short.MAX_VALUE))
        );
        jp_dados_residenciaisLayout.setVerticalGroup(
            jp_dados_residenciaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jp_dados_residenciaisLayout.createSequentialGroup()
                .addGroup(jp_dados_residenciaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(tf_endereco, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbl_endereco)
                    .addComponent(lbl_numero)
                    .addComponent(tf_numero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jp_dados_residenciaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jp_dados_residenciaisLayout.createSequentialGroup()
                        .addComponent(lbl_apto)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(lbl_cidade))
                    .addGroup(jp_dados_residenciaisLayout.createSequentialGroup()
                        .addGroup(jp_dados_residenciaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(tf_apto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lbl_uf)
                            .addComponent(cb_uf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jp_dados_residenciaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(tf_cidade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lbl_bairro)
                            .addComponent(tf_bairro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(21, Short.MAX_VALUE))
        );

        jp_dados_de_contato.setBackground(new java.awt.Color(255, 255, 255));
        jp_dados_de_contato.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Dados de Contato:", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Calibri", 1, 16), new java.awt.Color(0, 102, 153))); // NOI18N

        lbl_email.setFont(new java.awt.Font("Calibri", 1, 16)); // NOI18N
        lbl_email.setText("E-mail:");

        tf_email.setEditable(false);
        tf_email.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N

        lbl_fone_fax.setFont(new java.awt.Font("Calibri", 1, 16)); // NOI18N
        lbl_fone_fax.setText("Fone/Fax:*");

        tf_telefone.setEditable(false);
        try {
            tf_telefone.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(##)####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        tf_telefone.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N

        lbl_celular.setFont(new java.awt.Font("Calibri", 1, 16)); // NOI18N
        lbl_celular.setText("Celular:");

        tf_celular.setEditable(false);
        try {
            tf_celular.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(##)####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        tf_celular.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N

        javax.swing.GroupLayout jp_dados_de_contatoLayout = new javax.swing.GroupLayout(jp_dados_de_contato);
        jp_dados_de_contato.setLayout(jp_dados_de_contatoLayout);
        jp_dados_de_contatoLayout.setHorizontalGroup(
            jp_dados_de_contatoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jp_dados_de_contatoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jp_dados_de_contatoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lbl_email)
                    .addComponent(lbl_fone_fax))
                .addGap(23, 23, 23)
                .addGroup(jp_dados_de_contatoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jp_dados_de_contatoLayout.createSequentialGroup()
                        .addComponent(tf_telefone, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(lbl_celular)
                        .addGap(18, 18, 18)
                        .addComponent(tf_celular, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(tf_email, javax.swing.GroupLayout.PREFERRED_SIZE, 258, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(190, Short.MAX_VALUE))
        );
        jp_dados_de_contatoLayout.setVerticalGroup(
            jp_dados_de_contatoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jp_dados_de_contatoLayout.createSequentialGroup()
                .addGroup(jp_dados_de_contatoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbl_email)
                    .addComponent(tf_email, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jp_dados_de_contatoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbl_fone_fax)
                    .addComponent(tf_telefone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbl_celular)
                    .addComponent(tf_celular, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jp_pesquisa.setBackground(new java.awt.Color(255, 255, 255));
        jp_pesquisa.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Pesquisa:", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Calibri", 1, 18), new java.awt.Color(0, 102, 153))); // NOI18N

        lbl_filtrar.setFont(new java.awt.Font("Calibri", 1, 16)); // NOI18N
        lbl_filtrar.setText("Filtrar por:");

        cb_filtrar.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N
        cb_filtrar.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Todos", "Código", "Nome" }));

        lbl_igual.setText("=");

        tf_pesquisar.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N

        btn_pesquisar.setText("Pesquisar");
        btn_pesquisar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_pesquisarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jp_pesquisaLayout = new javax.swing.GroupLayout(jp_pesquisa);
        jp_pesquisa.setLayout(jp_pesquisaLayout);
        jp_pesquisaLayout.setHorizontalGroup(
            jp_pesquisaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jp_pesquisaLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lbl_filtrar)
                .addGap(18, 18, 18)
                .addComponent(cb_filtrar, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lbl_igual)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tf_pesquisar, javax.swing.GroupLayout.PREFERRED_SIZE, 174, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btn_pesquisar)
                .addContainerGap())
        );
        jp_pesquisaLayout.setVerticalGroup(
            jp_pesquisaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jp_pesquisaLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jp_pesquisaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbl_filtrar)
                    .addComponent(cb_filtrar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbl_igual)
                    .addComponent(tf_pesquisar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btn_pesquisar))
                .addContainerGap(23, Short.MAX_VALUE))
        );

        jp_paciente.setBackground(new java.awt.Color(255, 255, 255));
        jp_paciente.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Pacientes:", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Calibri", 1, 18), new java.awt.Color(0, 102, 153))); // NOI18N

        jt_pacientes.setAutoCreateRowSorter(true);
        jt_pacientes.setFont(new java.awt.Font("Calibri", 0, 10)); // NOI18N
        jt_pacientes.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Cód", "Nome", "Dentista", "RG", "CPF", "E-mail", "Telefone", "Celular", "Endereço", "Número", "Apto", "UF", "Cidade", "Bairro"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false, false, false, false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jt_pacientes.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
        jScrollPane1.setViewportView(jt_pacientes);

        javax.swing.GroupLayout jp_pacienteLayout = new javax.swing.GroupLayout(jp_paciente);
        jp_paciente.setLayout(jp_pacienteLayout);
        jp_pacienteLayout.setHorizontalGroup(
            jp_pacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jp_pacienteLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1)
                .addContainerGap())
        );
        jp_pacienteLayout.setVerticalGroup(
            jp_pacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jp_pacienteLayout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 302, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));
        jPanel1.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));

        btn_novo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/img_novo.png"))); // NOI18N
        btn_novo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_novoActionPerformed(evt);
            }
        });

        btn_excluir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/img_excluir.png"))); // NOI18N
        btn_excluir.setMaximumSize(new java.awt.Dimension(65, 41));
        btn_excluir.setMinimumSize(new java.awt.Dimension(65, 41));
        btn_excluir.setPreferredSize(new java.awt.Dimension(65, 41));

        btn_salvar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/img_salvar.png"))); // NOI18N
        btn_salvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_salvarActionPerformed(evt);
            }
        });

        btn_alterar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/img_alterar.png"))); // NOI18N
        btn_alterar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_alterarActionPerformed(evt);
            }
        });

        btn_editar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/img_editar.png"))); // NOI18N
        btn_editar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_editarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(btn_novo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btn_salvar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btn_excluir, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btn_editar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btn_alterar)
                .addGap(0, 830, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(btn_novo)
                    .addComponent(btn_salvar)
                    .addComponent(btn_excluir, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btn_editar)
                    .addComponent(btn_alterar))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        btn_imagem.setText("Imagem");
        btn_imagem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_imagemActionPerformed(evt);
            }
        });

        jFileChooser.setDialogType(javax.swing.JFileChooser.SAVE_DIALOG);
        jFileChooser.setCurrentDirectory(new java.io.File("C:\\Users\\Alessandro\\Desktop"));
        jFileChooser.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jFileChooserActionPerformed(evt);
            }
        });

        jLabel1.setText("jLabel1");

        jm_menu_opcoes.setText("Opções");
        jm_menu_opcoes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jm_menu_opcoesActionPerformed(evt);
            }
        });

        jm_menu_backup.setText("Backup");
        jm_menu_backup.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jm_menu_backupActionPerformed(evt);
            }
        });
        jm_menu_opcoes.add(jm_menu_backup);

        jm_menu_restaurar_backup.setText("Restaurar backup");
        jm_menu_restaurar_backup.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jm_menu_restaurar_backupActionPerformed(evt);
            }
        });
        jm_menu_opcoes.add(jm_menu_restaurar_backup);

        jm_menu_usuarios.setText("Gerenciar usuários");
        jm_menu_opcoes.add(jm_menu_usuarios);

        jm_menu_sair.setText("Sair");
        jm_menu_sair.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jm_menu_sairActionPerformed(evt);
            }
        });
        jm_menu_opcoes.add(jm_menu_sair);

        jm_menu.add(jm_menu_opcoes);

        jm_menu_gerenciar.setText("Gerenciar");

        jm_menu_clinicas.setText("Clinicas");
        jm_menu_clinicas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jm_menu_clinicasActionPerformed(evt);
            }
        });
        jm_menu_gerenciar.add(jm_menu_clinicas);

        jm_menu_dentistas.setText("Dentistas");
        jm_menu_dentistas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jm_menu_dentistasActionPerformed(evt);
            }
        });
        jm_menu_gerenciar.add(jm_menu_dentistas);

        jm_menu_pacientes.setText("Pacientes");
        jm_menu_pacientes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jm_menu_pacientesActionPerformed(evt);
            }
        });
        jm_menu_gerenciar.add(jm_menu_pacientes);

        jm_menu_ordem_de_servico.setText("Ordem de Serviço");
        jm_menu_ordem_de_servico.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jm_menu_ordem_de_servicoActionPerformed(evt);
            }
        });
        jm_menu_gerenciar.add(jm_menu_ordem_de_servico);

        jm_menu.add(jm_menu_gerenciar);

        jm_menu_ajuda.setText("Ajuda");

        jm_menu_conteudo_ajuda.setText("Conteúdo da ajuda");
        jm_menu_ajuda.add(jm_menu_conteudo_ajuda);

        jm_menu_sobre.setText("Sobre");
        jm_menu_ajuda.add(jm_menu_sobre);

        jm_menu.add(jm_menu_ajuda);

        setJMenuBar(jm_menu);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jp_dados_de_contato, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jp_dados_residenciais, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jp_dados_do_paciente, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jp_paciente, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jp_pesquisa, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(btn_imagem)
                        .addGap(109, 109, 109)
                        .addComponent(jLabel1)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(295, 295, 295)
                    .addComponent(jFileChooser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(296, Short.MAX_VALUE)))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jp_pesquisa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jp_paciente, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jp_dados_do_paciente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(5, 5, 5)
                        .addComponent(jp_dados_de_contato, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jp_dados_residenciais, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btn_imagem)
                    .addComponent(jLabel1))
                .addContainerGap(40, Short.MAX_VALUE))
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(111, 111, 111)
                    .addComponent(jFileChooser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(111, Short.MAX_VALUE)))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btn_novoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_novoActionPerformed
        limparCampos();
        habilitarCampos();
        incrementarCodigo();
        btn_salvar.setEnabled(true);
    }//GEN-LAST:event_btn_novoActionPerformed

    private void btn_salvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_salvarActionPerformed
        /*
         * id_dentista é auto incremental
         */

        PacienteController pacienteController = new PacienteController();
        nome_dentista = cb_dentista.getSelectedItem() + "";//busca o nome da clinica que esta no cb_clinica.
        id_dentista = pacienteController.buscarIDDentista(nome_dentista);//busca o id_clinica a partir do nome selecionado no cb_clinica.
        nome = tf_nome.getText();
        apto = tf_apto.getText();
        bairro = tf_bairro.getText();
        celular = tf_celular.getText();
        cidade = tf_cidade.getText();
        rg = tf_rg.getText();
        cpf = tf_cpf.getText();
        email = tf_email.getText();
        endereco = tf_endereco.getText();
        numero = tf_numero.getText();
        cpf = tf_cpf.getText();
        telefone = tf_telefone.getText();
        uf = cb_uf.getSelectedItem() + "";

        if (validarFormulario()) {
            if (pacienteController.cadastrarPaciente(id_dentista, nome, rg, cpf, email, telefone, celular, endereco, numero, apto, uf, cidade, bairro)) {
                JOptionPane.showMessageDialog(this, "Paciente cadastrado com sucesso.");
                limparCampos();
            } else {
                JOptionPane.showMessageDialog(this, "Problema na gravação.");
            }
        } else {
            JOptionPane.showMessageDialog(this, "Campos com * são obrigatórios.");
        }
    }//GEN-LAST:event_btn_salvarActionPerformed

    private void btn_alterarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_alterarActionPerformed
        PacienteController pacienteController = new PacienteController();
        id_paciente = Integer.parseInt(tf_codigo.getText());
        id_dentista = pacienteController.buscarIDDentista(cb_dentista.getSelectedItem() + "");
        nome = tf_nome.getText();
        apto = tf_apto.getText();
        bairro = tf_bairro.getText();
        celular = tf_celular.getText();
        cidade = tf_cidade.getText();
        rg = tf_rg.getText();
        cpf = tf_cpf.getText();
        email = tf_email.getText();
        endereco = tf_endereco.getText();
        numero = tf_numero.getText();
        telefone = tf_telefone.getText();
        uf = cb_uf.getSelectedItem() + "";

        if (validarFormulario()) {
            if (pacienteController.alterarPaciente(id_paciente, id_dentista, nome, rg, cpf, email, telefone, celular, endereco, numero, apto, uf, cidade, bairro)) {
                JOptionPane.showMessageDialog(this, "Paciente alterado com sucesso.");
                desabilitarCampos();
                limparCampos();
            } else {
                JOptionPane.showMessageDialog(this, "Problema na gravação.");
            }
        } else {
            JOptionPane.showMessageDialog(this, "Campos com * são obrigatórios.");
        }
    }//GEN-LAST:event_btn_alterarActionPerformed

    private void btn_editarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_editarActionPerformed
        btn_salvar.setEnabled(false);
        PacienteController pacienteController = new PacienteController();
        int linha = jt_pacientes.getSelectedRow();
        //int id_clinica = dentistaController.buscarIDProx(linha,1);
        
        int id_paciente = pacienteController.buscarIDdeTabelas(linha, 0);
        habilitarCampos();
        //if(id != 0){
        pacienteController.editarPaciente(id_paciente);
        //}
        //else{
        //  JOptionPane.showMessageDialog(this,"Selecione um registro.");
        //}
    }//GEN-LAST:event_btn_editarActionPerformed

    private void btn_pesquisarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_pesquisarActionPerformed
        btn_salvar.setEnabled(false);
        limparCampos();
        desabilitarCampos();
        String filtrar_por = cb_filtrar.getSelectedItem()+"";//busca tipo de pesquisa.
        String pesquisar = tf_pesquisar.getText();//busca valor a ser pesquisado.
        limparTabelaPacientes();//limpa a tabela de dentistas para uma nova pesquisa.
        PacienteController pacienteController = new PacienteController();
        pacienteController.buscarPacientes(filtrar_por,pesquisar);//passa o tipo de pesquisa e o valor a ser pesquisado.
    }//GEN-LAST:event_btn_pesquisarActionPerformed

    private void btn_imagemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_imagemActionPerformed
       jFileChooser.setVisible(true);
        
        int val = jFileChooser.showOpenDialog(null);              
        if(val == JFileChooser.APPROVE_OPTION) {  
        String endereco  = jFileChooser.getSelectedFile().getPath();
        File file;
        file = jFileChooser.getSelectedFile();
        String name = jFileChooser.getName(file);
        
        Image img=null;
        
        
        
        //int h = jFileChooser.getHeight();
        //int w = jFileChooser.getWidth();
        try{ 
            System.out.println(endereco);
            System.out.println(file);
            System.out.println(name);
            //buscarImagem(endereco);                  
            }catch(Exception e){JOptionPane.showMessageDialog(this,"Erro");}
        }
    }//GEN-LAST:event_btn_imagemActionPerformed

        private void jFileChooserActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jFileChooserActionPerformed



 }//GEN-LAST:event_jFileChooserActionPerformed

    private void jm_menu_backupActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jm_menu_backupActionPerformed
        Base base = new Base();
        int resp = JOptionPane.showConfirmDialog(null, "Realizar Backup?", "Backup", JOptionPane.YES_NO_OPTION);
        if (resp == JOptionPane.YES_OPTION) {
            base.backup();
        }
    }//GEN-LAST:event_jm_menu_backupActionPerformed

    private void jm_menu_restaurar_backupActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jm_menu_restaurar_backupActionPerformed
        Base base = new Base();
        int resp = JOptionPane.showConfirmDialog(null, "Realizar Backup?", "Backup", JOptionPane.YES_NO_OPTION);
        if (resp == JOptionPane.YES_OPTION) {
            base.restaurarBackup();
        }
    }//GEN-LAST:event_jm_menu_restaurar_backupActionPerformed

    private void jm_menu_sairActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jm_menu_sairActionPerformed
        dispose();
    }//GEN-LAST:event_jm_menu_sairActionPerformed

    private void jm_menu_opcoesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jm_menu_opcoesActionPerformed

   }//GEN-LAST:event_jm_menu_opcoesActionPerformed

    private void jm_menu_clinicasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jm_menu_clinicasActionPerformed
        frm_clinicas clinicas = new frm_clinicas(nivel_acesso);
        clinicas.setVisible(true);
        // this.setVisible(false);
    }//GEN-LAST:event_jm_menu_clinicasActionPerformed

    private void jm_menu_dentistasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jm_menu_dentistasActionPerformed
        frm_dentistas dentistas = new frm_dentistas(nivel_acesso);
        dentistas.setVisible(true);
        //  this.setVisible(false);
    }//GEN-LAST:event_jm_menu_dentistasActionPerformed

    private void jm_menu_pacientesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jm_menu_pacientesActionPerformed
        frm_pacientes pacientes = new frm_pacientes(nivel_acesso);
        pacientes.setVisible(true);
        // this.setVisible(false);
    }//GEN-LAST:event_jm_menu_pacientesActionPerformed

    private void jm_menu_ordem_de_servicoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jm_menu_ordem_de_servicoActionPerformed
        frm_ordem_de_servico os = new frm_ordem_de_servico(nivel_acesso);
        os.setVisible(true);
        // this.setVisible(false);
    }//GEN-LAST:event_jm_menu_ordem_de_servicoActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(frm_clinicas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(frm_clinicas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(frm_clinicas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(frm_clinicas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new frm_pacientes(nivel_acesso).setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btn_alterar;
    private javax.swing.JButton btn_editar;
    private javax.swing.JButton btn_excluir;
    private javax.swing.JButton btn_imagem;
    private javax.swing.JButton btn_novo;
    private javax.swing.JButton btn_pesquisar;
    private javax.swing.JButton btn_salvar;
    public static javax.swing.JComboBox cb_dentista;
    private javax.swing.JComboBox cb_filtrar;
    public static javax.swing.JComboBox cb_uf;
    private javax.swing.JFileChooser jFileChooser;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JMenuBar jm_menu;
    private javax.swing.JMenu jm_menu_ajuda;
    private javax.swing.JMenuItem jm_menu_backup;
    private javax.swing.JMenuItem jm_menu_clinicas;
    private javax.swing.JMenuItem jm_menu_conteudo_ajuda;
    private javax.swing.JMenuItem jm_menu_dentistas;
    private javax.swing.JMenu jm_menu_gerenciar;
    private javax.swing.JMenu jm_menu_opcoes;
    private javax.swing.JMenuItem jm_menu_ordem_de_servico;
    private javax.swing.JMenuItem jm_menu_pacientes;
    private javax.swing.JMenuItem jm_menu_restaurar_backup;
    private javax.swing.JMenuItem jm_menu_sair;
    private javax.swing.JMenuItem jm_menu_sobre;
    public static javax.swing.JMenuItem jm_menu_usuarios;
    private javax.swing.JPanel jp_dados_de_contato;
    private javax.swing.JPanel jp_dados_do_paciente;
    private javax.swing.JPanel jp_dados_residenciais;
    private javax.swing.JPanel jp_paciente;
    private javax.swing.JPanel jp_pesquisa;
    public static javax.swing.JTable jt_pacientes;
    private javax.swing.JLabel lbl_apto;
    private javax.swing.JLabel lbl_bairro;
    private javax.swing.JLabel lbl_celular;
    private javax.swing.JLabel lbl_cidade;
    private javax.swing.JLabel lbl_codigo;
    private javax.swing.JLabel lbl_cpf;
    private javax.swing.JLabel lbl_dentista;
    private javax.swing.JLabel lbl_email;
    private javax.swing.JLabel lbl_endereco;
    private javax.swing.JLabel lbl_filtrar;
    private javax.swing.JLabel lbl_fone_fax;
    private javax.swing.JLabel lbl_igual;
    private javax.swing.JLabel lbl_nome;
    private javax.swing.JLabel lbl_numero;
    private javax.swing.JLabel lbl_rg;
    private javax.swing.JLabel lbl_uf;
    public static javax.swing.JTextField tf_apto;
    public static javax.swing.JTextField tf_bairro;
    public static javax.swing.JFormattedTextField tf_celular;
    public static javax.swing.JTextField tf_cidade;
    public static javax.swing.JTextField tf_codigo;
    public static javax.swing.JFormattedTextField tf_cpf;
    public static javax.swing.JTextField tf_email;
    public static javax.swing.JTextField tf_endereco;
    public static javax.swing.JTextField tf_nome;
    public static javax.swing.JTextField tf_numero;
    private javax.swing.JTextField tf_pesquisar;
    public static javax.swing.JFormattedTextField tf_rg;
    public static javax.swing.JFormattedTextField tf_telefone;
    // End of variables declaration//GEN-END:variables
}
